package com.nononsenseapps.feeder.util

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import com.gitee.wsl.android.eventbus.SweetFlowBus

object EventBusUtils {

    fun fireSyncStateChange(event:SyncState)= SweetFlowBus.post("sync",event)
    fun addSyncStateChangeListener(owner: LifecycleOwner,observer: Observer<SyncState>)=
        SweetFlowBus.observe(owner,"sync",observer)


    fun getNotifyStateFlow()= SweetFlowBus.getEventFlow<SyncState>("notify")
    fun fireNotifyStateChange(event:SyncState)= SweetFlowBus.post("notify",event)
    fun addNotifyStateChangeListener(owner: LifecycleOwner,observer: Observer<SyncState>)=
        SweetFlowBus.observe(owner,"notify",observer)

    fun getCurrentlyFabShowFlow()= SweetFlowBus.getEventFlow<Boolean>("fab_show")
    fun fireCurrentlyFabShow(event:Boolean)= SweetFlowBus.post("fab_show",event)
    fun addCurrentlyFabShowStateChangeListener(owner: LifecycleOwner,observer: Observer<Boolean>)=
        SweetFlowBus.observe(owner,"fab_show",observer)

}

data class SyncState(val id:Long, val tag:String, var description:String, var success:Boolean=true, var count:Int=0, var notify:Boolean=false){
    fun appError(err:String){
        this.success=false
        this.description= "$description\t$err: -> X \n"
    }

    fun appSuccess(sucStr:String){
        this.description=description+"\t"+sucStr+"\n"
    }
}


